#include <avr/wdt.h>
#include <Timer.h>
#include "Wire.h"
#include <SD.h>
#include <Wstring.h>


#define DELAY1S     1000
#define DELAY5S     5000
#define MAX         4090
#define MIN         0
#define adres       4 //I2C adres
#define DEBUG


File myFile;
String buf;
char character;
int inputnode,inputpin,outputnode,outputpin;
const int chipSelect = 10;


void setup()
{
  Serial.begin(9600);
  Serial.println("Starting...");
  pinMode(10, OUTPUT);
  
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  getSettings();
}  
void getSettings()
{
   
  myFile = SD.open("arduino.csv");
   while (myFile.available()) {
     while (character !='E'){
       while (character !='\n'){
        while(character != ','){
           character = myFile.read();
           buf.concat(character);
        Serial.print ("buffer1 = "); 
        Serial.println (buf);   
       }
       buf="";
      inputnode=buf.toFloat();
      character=NULL;
      /*
      while(character != ','){
           character = myFile.read();
           buf.concat(character);
           Serial.print ("buffer2 = "); 
           Serial.println (buf);   
       }
       buf="";
      inputpin=buf.toFloat();
      character=NULL;
     while(character != ','){
           character = myFile.read();
           buf.concat(character);
           Serial.print ("buffer3 = "); 
           Serial.println (buf);   
       }
       buf="";
      outputnode=buf.toFloat();
      character=NULL;
      
      while(character != ','){
           character = myFile.read();
           buf.concat(character);
        Serial.print ("buffer4 = "); 
        Serial.println (buf);   
       }
       buf="";
      outputpin=buf.toFloat();
      character=NULL; 
      while(character != ','){
           character = myFile.read();
           buf.concat(character);
        Serial.print ("buffer5 = "); 
        Serial.println (buf);   
       }
       buf="";
      outputpin=buf.toFloat();
      character=NULL; 
      */
      }
     }
     return;
     }
   myFile.close();
   Serial.print ("inputnode = ");
   Serial.println (inputnode);
   Serial.print ("inputpin = ");
   Serial.println (inputpin);
   Serial.print ("outputnode = ");
   Serial.println (outputnode);
   Serial.print ("outputpin = ");
   Serial.println (outputpin);
}   
       
void loop()
{
	// nothing happens after setup
}
